﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace Illusion
{
	// Token: 0x0200036E RID: 878
	public static class Utils
	{
		// Token: 0x0200036F RID: 879
		public static class Enum<T> where T : struct
		{
			// Token: 0x17000228 RID: 552
			// (get) Token: 0x060015FF RID: 5631 RVA: 0x00093D28 File Offset: 0x00091F28
			public static string[] Names
			{
				get
				{
					return Enum.GetNames(typeof(T));
				}
			}

			// Token: 0x17000229 RID: 553
			// (get) Token: 0x06001600 RID: 5632 RVA: 0x00093D3C File Offset: 0x00091F3C
			public static Array Values
			{
				get
				{
					return Enum.GetValues(typeof(T));
				}
			}

			// Token: 0x1700022A RID: 554
			// (get) Token: 0x06001601 RID: 5633 RVA: 0x00093D50 File Offset: 0x00091F50
			public static int Length
			{
				get
				{
					return Utils.Enum<T>.Values.Length;
				}
			}

			// Token: 0x06001602 RID: 5634 RVA: 0x00093D5C File Offset: 0x00091F5C
			public static void Each(Action<T> act)
			{
				IEnumerator enumerator = Utils.Enum<T>.Values.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						object obj = enumerator.Current;
						T obj2 = (T)((object)obj);
						act(obj2);
					}
				}
				finally
				{
					IDisposable disposable;
					if ((disposable = (enumerator as IDisposable)) != null)
					{
						disposable.Dispose();
					}
				}
			}

			// Token: 0x06001603 RID: 5635 RVA: 0x00093DC0 File Offset: 0x00091FC0
			[Conditional("UNITY_ASSERTIONS")]
			private static void Check(bool condition, string message)
			{
			}

			// Token: 0x06001604 RID: 5636 RVA: 0x00093DC4 File Offset: 0x00091FC4
			public static bool Contains(string key, bool ignoreCase = false)
			{
				return Utils.Enum<T>.FindIndex(key, ignoreCase) != -1;
			}

			// Token: 0x06001605 RID: 5637 RVA: 0x00093DD4 File Offset: 0x00091FD4
			public static int FindIndex(string key, bool ignoreCase = false)
			{
				string[] names = Utils.Enum<T>.Names;
				for (int i = 0; i < names.Length; i++)
				{
					if (string.Compare(names[i], key, ignoreCase) == 0)
					{
						return i;
					}
				}
				return -1;
			}

			// Token: 0x06001606 RID: 5638 RVA: 0x00093E10 File Offset: 0x00092010
			public static T Cast(string key)
			{
				return (T)((object)Enum.Parse(typeof(T), key));
			}

			// Token: 0x06001607 RID: 5639 RVA: 0x00093E28 File Offset: 0x00092028
			public static T Cast(int no)
			{
				Type typeFromHandle = typeof(T);
				return (T)((object)Enum.ToObject(typeFromHandle, no));
			}

			// Token: 0x06001608 RID: 5640 RVA: 0x00093E4C File Offset: 0x0009204C
			public static T Cast(uint sum)
			{
				return (T)((object)Enum.ToObject(typeof(T), sum));
			}

			// Token: 0x06001609 RID: 5641 RVA: 0x00093E64 File Offset: 0x00092064
			public static T Cast(ulong sum)
			{
				return (T)((object)Enum.ToObject(typeof(T), sum));
			}

			// Token: 0x0600160A RID: 5642 RVA: 0x00093E7C File Offset: 0x0009207C
			public static Utils.Enum<T>.EnumerateParameter Enumerate()
			{
				return new Utils.Enum<T>.EnumerateParameter();
			}

			// Token: 0x1700022B RID: 555
			// (get) Token: 0x0600160B RID: 5643 RVA: 0x00093E84 File Offset: 0x00092084
			public static T Nothing
			{
				get
				{
					return default(T);
				}
			}

			// Token: 0x1700022C RID: 556
			// (get) Token: 0x0600160C RID: 5644 RVA: 0x00093E9C File Offset: 0x0009209C
			public static T Everything
			{
				get
				{
					ulong sum = 0UL;
					Utils.Enum<T>.Each(delegate(T o)
					{
						sum += Convert.ToUInt64(o);
					});
					return Utils.Enum<T>.Cast(sum);
				}
			}

			// Token: 0x0600160D RID: 5645 RVA: 0x00093ED4 File Offset: 0x000920D4
			public static T Normalize(T value)
			{
				return Utils.Enum<T>.Cast((ulong)(Convert.ToInt64(value) & Convert.ToInt64(Utils.Enum<T>.Everything)));
			}

			// Token: 0x0600160E RID: 5646 RVA: 0x00093EF8 File Offset: 0x000920F8
			public static string ToString(T value)
			{
				StringBuilder text = new StringBuilder();
				Utils.Enum<T>.Each(delegate(T e)
				{
					ulong num = Convert.ToUInt64(e);
					if ((Convert.ToUInt64(value) & num) == num)
					{
						text.AppendFormat("{0} | ", e);
					}
				});
				return text.ToString();
			}

			// Token: 0x02000370 RID: 880
			public class EnumerateParameter
			{
				// Token: 0x06001610 RID: 5648 RVA: 0x00093F44 File Offset: 0x00092144
				public IEnumerator<T> GetEnumerator()
				{
					IEnumerator enumerator = Utils.Enum<T>.Values.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							object obj = enumerator.Current;
							T e = (T)((object)obj);
							yield return e;
						}
					}
					finally
					{
						IDisposable disposable;
						if ((disposable = (enumerator as IDisposable)) != null)
						{
							disposable.Dispose();
						}
					}
					yield break;
				}
			}
		}

		// Token: 0x02000374 RID: 884
		public static class File
		{
			// Token: 0x0600161B RID: 5659 RVA: 0x00094148 File Offset: 0x00092348
			public static string[] Gets(string filePath, string searchFile)
			{
				List<string> list = new List<string>();
				if (Directory.Exists(filePath))
				{
					foreach (string path in Directory.GetDirectories(filePath))
					{
						list.AddRange(Directory.GetFiles(path, searchFile));
					}
				}
				return list.ToArray();
			}

			// Token: 0x0600161C RID: 5660 RVA: 0x00094198 File Offset: 0x00092398
			public static void GetAllFiles(string folder, string searchPattern, ref List<string> files)
			{
				files.AddRange(Directory.GetFiles(folder, searchPattern));
				foreach (string folder2 in Directory.GetDirectories(folder))
				{
					Utils.File.GetAllFiles(folder2, searchPattern, ref files);
				}
			}

			// Token: 0x0600161D RID: 5661 RVA: 0x000941DC File Offset: 0x000923DC
			public static List<string> GetPaths(string[] paths, string ext, SearchOption option)
			{
				List<string> list = new List<string>();
				if (Utils.File.callback0 == null)
				{
					Utils.File.callback0 = new Func<string, bool>(Directory.Exists);
				}
				foreach (IGrouping<bool, string> grouping in paths.GroupBy(Utils.File.callback0))
				{
					if (grouping.Key)
					{
						foreach (string path2 in grouping)
						{
							list.AddRange(Directory.GetFiles(path2, "*" + ext, option));
						}
					}
					else
					{
						list.AddRange(from path in grouping
						where Path.GetExtension(path) == ext
						select path);
					}
				}
				return list;
			}

			// Token: 0x0600161E RID: 5662 RVA: 0x000942E8 File Offset: 0x000924E8
			public static string ConvertPath(string path)
			{
				return path.Replace("\\", "/");
			}

			// Token: 0x0600161F RID: 5663 RVA: 0x000942FC File Offset: 0x000924FC
			public static object LoadFromBinaryFile(string path)
			{
				object obj = null;
				Utils.File.OpenRead(path, delegate(FileStream fs)
				{
					obj = new BinaryFormatter().Deserialize(fs);
				});
				return obj;
			}

			// Token: 0x06001620 RID: 5664 RVA: 0x00094330 File Offset: 0x00092530
			public static void SaveToBinaryFile(object obj, string path)
			{
				Utils.File.OpenWrite(path, false, delegate(FileStream fs)
				{
					new BinaryFormatter().Serialize(fs, obj);
				});
			}

			// Token: 0x06001621 RID: 5665 RVA: 0x00094360 File Offset: 0x00092560
			public static bool OpenRead(string filePath, Action<FileStream> act)
			{
				if (!System.IO.File.Exists(filePath))
				{
					return false;
				}
				using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
				{
					act(fileStream);
				}
				return true;
			}

			// Token: 0x06001622 RID: 5666 RVA: 0x000943B0 File Offset: 0x000925B0
			public static void OpenWrite(string filePath, bool isAppend, Action<FileStream> act)
			{
				if (!isAppend)
				{
					using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
					{
						act(fileStream);
					}
				}
				else
				{
					using (FileStream fileStream2 = new FileStream(filePath, FileMode.Append, FileAccess.Write))
					{
						act(fileStream2);
					}
				}
			}

			// Token: 0x06001623 RID: 5667 RVA: 0x00094428 File Offset: 0x00092628
			public static bool Read(string filePath, Action<StreamReader> act)
			{
				return Utils.File.OpenRead(filePath, delegate(FileStream fs)
				{
					using (StreamReader streamReader = new StreamReader(fs))
					{
						act(streamReader);
					}
				});
			}

			// Token: 0x06001624 RID: 5668 RVA: 0x00094454 File Offset: 0x00092654
			public static void Write(string filePath, bool isAppend, Action<StreamWriter> act)
			{
				Utils.File.OpenWrite(filePath, isAppend, delegate(FileStream fs)
				{
					using (StreamWriter streamWriter = new StreamWriter(fs))
					{
						act(streamWriter);
					}
				});
			}

			// Token: 0x040019DF RID: 6623
			[CompilerGenerated]
			private static Func<string, bool> callback0;
		}
	}
}
